/**
* Class representing a plugin container's declared interfaces that must be implemented in order to plug-in to it.
*/
jsx3.lang.Class.defineClass("tibco.admin.util.component.DeclaredInterface",
        jsx3.lang.Object,
        null,
        function(config) {

            /**
            * The fully-qualified name of the interface
            * @private
            */
            config.prototype.name = null;

            /**
            * The user-readable description of the interface and what it's used for
            * @private
            */
            config.prototype.description = null;

            /**
            * A {jsx3.util.List} of the {tibco.admin.util.component.ExtensionPoint} objects representing the extension
            * points handled by this interface
            * @private
            */
            config.prototype.extensionPoints = null;

            /**
            * Constructor for this class.
            *
            * @param doc {jsx3.xml.Entity} an xml node containing the information for a declared interface
            * @throws {tibco.admin.exception.InvalidComponentSchemaException} if the xml is invalid
            */
            config.prototype.init = function(doc) {
                this.jsxsuper();
                this.extensionPoints = new jsx3.util.List(0);
                var children = doc.getChildNodes().iterator();
                while(children.hasNext()) {
                    var child = children.next();
                    var childName = child.getNodeName();
                    if(childName == "interface_name") {
                        this.name = child.getValue();
                    }
                    else if(childName == "description") {
                        this.description = child.getValue();
                    }
                    else if(childName == "extension_points") {
                        var childEPs = child.getChildNodes().iterator();
                        while(childEPs.hasNext()) {
                            var childEP = childEPs.next();
                            var childEPName = childEP.getNodeName();
                            if(childEPName == "extension_point") {
                                this.extensionPoints.add(new tibco.admin.util.component.ExtensionPoint(childEP), this.extensionPoints.size());
                            }
                            else {
                                throw new tibco.admin.exception.InvalidComponentSchemaException("Unknown tag '" + childEPName + "' in the 'extension_points' tag of the component schema.  Supported tags are: extension_point");
                            }
                        }
                        if(this.extensionPoints.size() == 0) {
                            throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'extension_points' requires at least one 'extension_point' child tag.")
                        }
                    }
                    else {
                        throw new tibco.admin.exception.InvalidComponentSchemaException("Unknown tag '" + childName + "' in the 'decl_interface' tag of the component schema.  Supported tags are: interface_name, description, extension_point");
                    }
                }
                if(!this.name) {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'interface_name' is a required child of 'decl_interface' tag.")
                }
                if(jsx3.util.strTrim(this.name.trim()) == "") {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'interface_name' may not be empty.")
                }
                if(!this.description) {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'description' is a required child of 'decl_interface' tag.")
                }
                if(jsx3.util.strTrim(this.description.trim()) == "") {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'description' may not be empty.")
                }
                if(this.extensionPoints.size() == 0) {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'extension_points' is a required child of 'decl_interface' tag.")
                }
            }

            /**
            * Returns the fully-qualified class name of this interface
            *
            * @return {String} the fully-qualified class name of this interface
            */
            config.prototype.getName = function() {
                return this.name;
            }

            /**
            * Returns the description of this interface
            *
            * @return {String} the description of this plugin component
            */
            config.prototype.getDescription = function() {
                return this.description;
            }

            /**
            * Returns an iterator of the ids of the Extension Points whose interaction API is defined by this interface
            *
            * @return {jsx3.util.Iterator} an iterator of the ids {strings} of the Extension Points whose interaction API is
            *         defined by this interface
            */
            config.prototype.getExtensionPoints = function() {
                return this.extensionPoints.clone().iterator();
            }

            /**
            * Returns a string representing this object in the xml format specified by the component.xsd schema
            *
            * @param prepend {String} a string to be prepended to each line of the returned XML (useful for indenting)
            *
            * @returns {String} this Resources object as XML, as specified by the component.xsd schema
            */
            config.prototype.toString = function(prepend) {
                if(!prepend) {
                    prepend = "";
                }
                var ret = prepend + "<decl_interface>\n";
                if(this.name) {
                    ret += prepend + "   <interface_name>" + this.name + "</interface_name>\n";
                }
                if(this.description) {
                    ret += prepend + "   <description>" + this.description + "</description>\n";
                }
                var iter = this.extensionPoints.iterator();
                while(iter.hasNext()) {
                    ret += iter.next().toString(prepend +"   ");
                }
                ret += prepend + "</decl_interface>\n";
                return ret;
            }
        }
);